package com.niit.bc.biz.impl;

import com.niit.bc.bean.ListBean;
import com.niit.bc.biz.ListBiz;
import com.niit.bc.dao.ListDao;
import com.niit.bc.dao.impl.ListDaoImpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ListBizImpl implements ListBiz {

    ListDao listDao = new ListDaoImpl();

    public List <ListBean> findAllList() {
        List <ListBean> list = new ArrayList <ListBean>();
        ResultSet rs = listDao.findAllList();
        if (rs != null) {
            try {
                while (rs.next()) {
                    int index = 1;
                    ListBean listBean = new ListBean();
                    listBean.setTypeId(rs.getInt(index++));
                    listBean.setTypeName(rs.getString(index++));
                    listBean.setChildTypeId(rs.getInt(index++));
                    listBean.setChildTypeName(rs.getString(index++));

                    list.add(listBean);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return list;
    }

    public List <ListBean> findList(int typeId) {
        List <ListBean> list = new ArrayList <ListBean>();
        ResultSet rs = listDao.findList(typeId);
        if (rs != null) {
            try {
                while (rs.next()) {
                    int index = 1;
                    ListBean listBean = new ListBean();
                    listBean.setTypeId(rs.getInt(index++));
                    listBean.setTypeName(rs.getString(index++));
                    listBean.setChildTypeId(rs.getInt(index++));
                    listBean.setChildTypeName(rs.getString(index++));

                    list.add(listBean);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return list;
    }

    public List <ListBean> findListType() {
        List <ListBean> list = new ArrayList <ListBean>();
        ResultSet rs = listDao.findListType();
        if (rs != null) {
            try {
                while (rs.next()) {
                    int index = 1;
                    ListBean listBean = new ListBean();
                    listBean.setTypeId(rs.getInt(index++));
                    listBean.setTypeName(rs.getString(index++));

                    list.add(listBean);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return list;
    }

    public List <ListBean> findListChildType() {
        List <ListBean> list = new ArrayList <ListBean>();
        ResultSet rs = listDao.findListChildType();
        if (rs != null) {
            try {
                while (rs.next()) {
                    int index = 1;
                    ListBean listBean = new ListBean();
                    listBean.setTypeId(rs.getInt(index++));
                    listBean.setChildTypeId(rs.getInt(index++));
                    listBean.setChildTypeName(rs.getString(index++));

                    list.add(listBean);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return list;
    }

    public List <ListBean> findListChildTypeByTypeId(int typeId) {
        List <ListBean> list = new ArrayList <ListBean>();
        ResultSet rs = listDao.findListChildTypeByTypeId(typeId);
        if (rs != null) {
            try {
                while (rs.next()) {
                    int index = 1;
                    ListBean listBean = new ListBean();
                    listBean.setChildTypeId(rs.getInt(index++));
                    listBean.setChildTypeName(rs.getString(index++));

                    list.add(listBean);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return list;
    }

}
